<?php

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class InitWeb extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        //开启事物

        // 使用 数据迁移 来操作 创建 超级 管理员
        $time = date('Y-m-d H:i:s');
        $admin['id'] = 1;
        $admin['name'] = env('ADMIN_NAME');
        $admin['username'] = env('ADMIN_USER_NAME');
        $admin['password'] = bcrypt(env('ADMIN_PASSWORD'));
        $admin = DB::table('admins')->insert($admin);
        $permission = array(
            	array('action'=>'Home\IndexController@index','name'=>'首页','created_at'=>$time,'updated_at'=>$time),
                array('action'=>'Home\AdminController@index','name'=>'管理员列表','created_at'=>$time,'updated_at'=>$time),
                array('action'=>'Home\AdminController@password_reset','name'=>'管理员列表页／密码重置','created_at'=>$time,'updated_at'=>$time),
                array('action'=>'Home\AdminController@Add','name'=>'添加管理员','created_at'=>$time,'updated_at'=>$time),
                array('action'=>'Home\RoleController@index','name'=>'角色列表','created_at'=>$time,'updated_at'=>$time),
                array('action'=>'Home\RoleController@add','name'=>'添加角色','created_at'=>$time,'updated_at'=>$time),
                array('action'=>'Home\RoleController@delete','name'=>'删除角色','created_at'=>$time,'updated_at'=>$time),
                array('action'=>'Home\PermissionController@index','name'=>'权限列表','created_at'=>$time,'updated_at'=>$time),
                array('action'=>'Home\PermissionController@edit','name'=>'权限名编辑','created_at'=>$time,'updated_at'=>$time),
                array('action'=>'Home\RoleController@permission','name'=>'Home\RoleController@permission','created_at'=>$time,'updated_at'=>$time),
                array('action'=>'Home\RoleController@setPermission','name'=>'Home\RoleController@setPermission','created_at'=>$time,'updated_at'=>$time),
        );
        $permission = DB::table('permissions')->insert($permission);
        if($admin && $permission){
            // 提交事物
        }else{
            // 事物回滚
        }
    }
}
